package com.storage.web.controller.system;

import com.storage.common.annotation.Log;
import com.storage.common.core.controller.BaseController;
import com.storage.common.core.domain.AjaxResult;
import com.storage.common.core.domain.ServiceResponse;
import com.storage.common.core.page.TableDataInfo;
import com.storage.common.enums.BusinessType;
import com.storage.framework.web.OperationContext;
import com.storage.framework.web.enums.RequestOperation;
import com.storage.system.domain.StorageMessage;
import com.storage.system.domain.StorageNoticeMessage;
import com.storage.system.service.IStorageMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 留言 信息操作处理
 *
 * @author ruoyi
 * @date 2019-09-12
 */
@Api(tags = "留言 信息操作处理")
@RestController
public class StorageMessageController extends BaseController {

    @Autowired
    private IStorageMessageService storageMessageService;

    /**
     * 查询留言列表
     */
    @ApiOperation(value = "查询留言列表")
    @GetMapping("/system/message/list")
    @ResponseBody
    public TableDataInfo list(StorageMessage storageMessage, Integer pageNum, Integer pageSize) {
        ServiceResponse<TableDataInfo> response = storageMessageService.selectStorageMessageList(storageMessage, pageNum, pageSize);
        return response.getData();
    }

    /**
     * 新增留言
     */
    @ApiOperation(value = "新增留言")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping("/system/message/add")
    @ResponseBody
    public AjaxResult addSave(@RequestOperation OperationContext context,
                              @RequestBody StorageMessage storageMessage) {
        return storageMessageService.insertStorageMessage(context.getStorageUser(), storageMessage);
    }

    /**
     * 删除留言
     */
    @ApiOperation(value = "删除留言")
    @Log(title = "留言", businessType = BusinessType.DELETE)
    @PostMapping("/system/message/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(storageMessageService.deleteStorageMessageByIds(ids));
    }


    /**
     * 查询推送消息通知列表
     */
    @ApiOperation(value = "查询推送消息通知列表")
    @GetMapping("/system/notice/message/list")
    @ResponseBody
    public AjaxResult list(@RequestOperation OperationContext context,
                           StorageNoticeMessage storageNoticeMessage) {
        ServiceResponse<List<StorageNoticeMessage>> response = storageMessageService.selectStorageNoticeMessageList(context.getStorageUser(), storageNoticeMessage);
        return AjaxResult.success(response.getData());
    }

    /**
     * 更新推送消息状态
     */
    @ApiOperation(value = "更新推送消息状态")
    @GetMapping("/system/notice/message/update/status")
    @ResponseBody
    public AjaxResult updateNoticeStatus(@RequestOperation OperationContext context,
                                         StorageNoticeMessage storageNoticeMessage) {
        ServiceResponse<StorageNoticeMessage> response = storageMessageService.updateNoticeStatus(context.getStorageUser(), storageNoticeMessage);
        return AjaxResult.success(response.getData());
    }
}
